package com.huluspace.military.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
public class UnifiedResponse<T> {
  private int code;        // 状态码：0成功，其他为失败
  private String message;  // 提示信息
  private T data;          // 返回的数据
  private long timestamp;  // 时间戳

  // 私有构造方法，统一通过静态方法创建
  private UnifiedResponse(int code, String message, T data) {
    this.code = code;
    this.message = message;
    this.data = data;
    this.timestamp = System.currentTimeMillis();
  }
  // 成功响应
  public static <T> UnifiedResponse<T> success(T data) {
    return new UnifiedResponse<>(0, "success", data);
  }
  public static <T> UnifiedResponse<T> success(String message, T data) {
    return new UnifiedResponse<>(0, message, data);
  }
  // 失败响应
  public static <T> UnifiedResponse<T> error(int code, String message) {
    return new UnifiedResponse<>(code, message, null);
  }
  public static <T> UnifiedResponse<T> error(String message) {
    return new UnifiedResponse<>(-1, message, null);
  }
}

